#include <iostream>
//#include <unordered_set>
#include <set>
#include <algorithm>
#include "Horse.h"
#include "Board.h"
#include <limits>

//#if defined _MSC_VER
//#include <hash_set>
//using namespace stdext;
//#elif __GNUC__==4 && __GNUC_MINOR__>2
//#include <hash_set>
//using namespace __gnu_cxx;
//#elif defined __GNUC__
//#include <ext/hash_set>
//using namespace __gnu_cxx;
//#endif

using namespace std;


bool checkInput(size_t num, size_t low, size_t hi = 1000)
{
	if (!cin)
	{
		cerr<<"Only numbers are allowed."<<endl;
		return false;
	}
	if (num < low || num > hi)
	{
		cerr << "Out of range. Should be within ["<<low<<','<<hi<<"]."<<endl;
		return false;
	}
	return true;
}

int main(int argc, char** argv) {
	srand((unsigned)time(0));
	/*
	input:
	n .. velikost sachovnice
	k .. pocet jezdcu (n ≤ k ≤ n*(n+1)/2)
	q .. max pocet nahodnych tahu (n ≤ q ≤ n*n)
	*/
	size_t n;
	size_t k;
	size_t q;
	
	cerr << "Velikost sachovnice (>=5):\n";
	cin >> n;
	if(!checkInput(n,5)){
		return 1;
	}
	
	cerr << "Pocet jezdcu ([" << n << "," << n*(n+1)/2 << "]):\n";
	cin >> k;
	if(!checkInput(k,n,n*(n+1)/2)){
		return 1;
	}
	
	cerr << "Pocet tahu([" << n << "," << n*n << "]):\n";
	cin >> q;
	if(!checkInput(q,n,n*n)){
		return 1;
	}

	Board b(n);
	b.putHorses(k);
	cerr << b << endl;
	b.shuffle(q);
	cerr << b << endl;
	b.printFileFormat(cout);

	return 0;
}